<!doctype html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta content="always" name="referrer">
	<#include "../common/header.html">

</head>
<body>
<!--最外面的灰底框,用于与ifram区别开-->
<div class="col-xs-12 lightgray_div" >
	<!--白底框-->
	<div class="col-xs-12 white_div">
		<!--返回按钮-->
		<h4 class="back_div"> <a href="javascript:history.back()" style="font-size: 16px; color: black; " >< 返回</a></h4>
		<div class="row all_input_div" style="margin-top: 8px">
			<div class="col-xs-6">
				<form class="form-horizontal" role="form" id="form1">
					<input type="hidden" name="id" id="id" value="${id!?html}"/>
					<div class="form-group">
						<label class="col-xs-2 control-label"><em class="text-red">*</em>字典类型</label>
						<div class="col-xs-10">
							<input type="hidden" class="form-control input_50b" name="type_id" id="type_id" value="${type_id!?html}">
							<input type="text" class="form-control input_50b" disabled id="type" >
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-2 control-label"><em class="text-red">*</em>字典值</label>
						<div class="col-xs-10" >
							<input type="text" class="form-control input_50b"   id="name" name="name"
								   placeholder="请输入字典名称,如:启用">
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-2 control-label"><em class="text-red">*</em>序号</label>
						<div class="col-xs-10">
							<input type="text" class="form-control input_50b"  name="sort" id="sort" oninput="value=value.replace(/[^\d]/g,'')"
								   placeholder="请输入序号">
						</div>
					</div>

					<div class="form-group">
						<label class="col-xs-2 control-label">描述</label>
						<div class="col-xs-10">
							<textarea type="text" class="form-control input_50b" style="height:120px;resize:none;" id="describe_info" name="describe_info" placeholder="详细描述字典值的含义"></textarea>
						</div>
					</div>

				</form>
				<div  class="form-group ">
					<label class="col-xs-2 control-label"></label>
					<a class="gbn gbn-m" href="javascript:" id="btn_save" onclick="E.save();" >保存</a>
					<a class="gbn gbn-m gbn-red" href="javascript:" onclick="history.back();" >返回</a>
				</div>
			</div>
		</div>
	</div>
</div>

</body>
<#include "../common/layui_init.html">
<script type="text/javascript">
	var E={
		save:function(){
			var para=tool.paraArrayToLiteral($("#form1").serializeArray());
			$.post("${request.contextPath}/dict/add_or_edit",para,function(o){
				if(o.code==0){
					layer.msg(o.message);
					location.href=document.referrer;
				}else{
					layui_layer.error_alert(o.message);
				}
			});
		},
		load:function(){
			$.getJSON("${request.contextPath}/dict/getById",{id:$("#id").val()},function(o){
				if(o.code ==0){
					$("#form1").setFormValues(o.data);
				}
			});
		},
		load_dict_type:function(){
			$.getJSON("${request.contextPath}/dict_type/getById",{id:"${type_id!?html}"},function(o){
				console.log(o);
				if(o.code==0){
					$("#type").val(o.data.name+"("+o.data.code+")");
				}else{
					layui_layer.error_alert(o.message);
				}

			});

		}

	}
	$(function(){
		//回车点击事件 保存
		enter_event.event_save_click();
		$.ajaxSettings.async=false;
		var id=$("#id").val()
		E.load_dict_type()
		if(id!=null&&id!=""){
			E.load();
		}
	});
</script>
<#include "../common/footer-inner.html">
</html>
